﻿// --------------
// 作者:Vitity
// --------------

namespace NICWebApi.Extensions.RESTfulResult.Filter;

/// <summary>
/// 验证模型过滤器
/// </summary>
public class ValidateModelFilter : ActionFilterAttribute
{
    /// <summary>
    /// 验证模型
    /// </summary>
    /// <param name="context"></param>
    public override void OnActionExecuting(ActionExecutingContext context)
    {
        // 拦截模型验证，并将其改成BadRequest
        if (!context.ModelState.IsValid)
        {
            context.Result = new BadRequestObjectResult(context.ModelState);
        }
    }
}